package com.zhuyuan.database.config;

import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.zhuyuan.database.scope.DataScopeInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: 张琳凯
 * @Description: TODO
 * @DateTime: 2025/3/3 11:26
 **/
@Configuration
public class MyBatisConfig {

    @Bean
    public ConfigurationCustomizer configurationCustomizer() {
        return configuration -> {
            MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
            // 数据范围
            mybatisPlusInterceptor.addInnerInterceptor(new DataScopeInterceptor());
            //分页
            PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
            mybatisPlusInterceptor.addInnerInterceptor(paginationInnerInterceptor);
            // 乐观锁
            mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
            // 防止全表更新与删除
            mybatisPlusInterceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
            configuration.addInterceptor(mybatisPlusInterceptor);
        };
    }
}